package com.lonwin.inspectionmanagement.mvp.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.ConfigBean;
import com.lonwin.inspectionmanagement.mvp.ui.activity.CruiseSearchActivity;
import com.lonwin.inspectionmanagement.mvp.ui.activity.SortOutRecordSearchActivity;

import java.util.List;

public class CruiseSearchItemAdapter extends BaseQuickAdapter<ConfigBean.RiverDatasBean.ChildrenBean,BaseViewHolder> {
    public CruiseSearchItemAdapter(@Nullable List<ConfigBean.RiverDatasBean.ChildrenBean> data) {
        super(R.layout.cruise_search_item_item,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ConfigBean.RiverDatasBean.ChildrenBean item) {
        helper.setText(R.id.cruise_search_item_item_txt,item.getName());
//        helper.addOnClickListener(R.id.cruise_search_item_item_txt);
        helper.getView(R.id.cruise_search_item_item_txt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (((Activity)mContext).getIntent().hasExtra("type"))
                {
                    //跳转到搜索结果界面，不返回到上一个界面
                    Intent intent=new Intent(mContext,SortOutRecordSearchActivity.class);
                    intent.putExtra("ChildrenBean",item);
                    mContext.startActivity(intent);
                    ((CruiseSearchActivity)mContext).killMyself();//结束自己
                    return;
                }
                Intent intent=new Intent();
                intent.putExtra("ChildrenBean",item);
                ((Activity)mContext).setResult(Activity.RESULT_OK,intent);
                ((CruiseSearchActivity)mContext).killMyself();
            }
        });

    }
}
